package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;

    @Override
    public void add(EmployeeBean employee) {
        mapper.insert(employee);
    }

    @Override
    public void del(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public void upDate(Integer id, Integer salary) {
        EmployeeBean employeeBean = mapper.selectById(id);
        employeeBean.setSalary(salary);

        mapper.updateById(employeeBean);
    }

    @Override
    public EmployeeBean findById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public IPage<EmployeeBean> cutByItem(Integer pageNO, String position, Integer minSalary, Integer maxSalary) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        if (position!=null&&!"".equals(position)){
            qw.like("e_position",position);
        }if (minSalary!=null){
            qw.ge("e_salary",minSalary);
        }if (maxSalary!=null){
            qw.le("e_salary",maxSalary);
        }
        return mapper.selectPage(new Page<>(pageNO,3),qw);
    }
}
